import os
import requests
from PIL import Image
from io import BytesIO

os.makedirs('ppt_imgs', exist_ok=True)

img_urls = [
    # 1. AI科技感封面
    'https://images.unsplash.com/photo-1465101046530-73398c7f28ca?auto=format&fit=crop&w=800&q=80',
    # 2. 抽象科技背景
    'https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=crop&w=800&q=80',
    # 3. AI大脑/人工智能
    'https://images.unsplash.com/photo-1517694712202-14dd9538aa97?auto=format&fit=crop&w=800&q=80',
    # 4. 虚拟角色/NPC
    'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?auto=format&fit=crop&w=800&q=80',
    # 5. 游戏地图/关卡
    'https://images.unsplash.com/photo-1508610048659-a06b669e4c47?auto=format&fit=crop&w=800&q=80',
    # 6. 自动化测试/代码
    'https://images.unsplash.com/photo-1519389950473-47ba0277781c?auto=format&fit=crop&w=800&q=80',
    # 7. 大数据/推荐系统
    'https://images.unsplash.com/photo-1465101178521-c1a9136a3b99?auto=format&fit=crop&w=800&q=80',
    # 8. 云游戏/服务器
    'https://images.unsplash.com/photo-1464983953574-0892a716854b?auto=format&fit=crop&w=800&q=80',
    # 9. 反外挂/安全
    'https://images.unsplash.com/photo-1465101046530-73398c7f28ca?auto=format&fit=crop&w=800&q=80',
    # 10. 未来科技/虚拟现实
    'https://images.unsplash.com/photo-1517694712202-14dd9538aa97?auto=format&fit=crop&w=800&q=80',
    # 11. 团队/致谢
    'https://images.unsplash.com/photo-1521737852567-6949f3f9f2b5?auto=format&fit=crop&w=800&q=80',
    # 12. 备用科技感配图
    'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?auto=format&fit=crop&w=800&q=80',
]

for idx, url in enumerate(img_urls, 1):
    fname = f'ppt_imgs/{idx}.png'
    try:
        headers = {'User-Agent': 'Mozilla/5.0'}
        resp = requests.get(url, headers=headers, timeout=15)
        resp.raise_for_status()
        img = Image.open(BytesIO(resp.content))
        img.save(fname)
        print(f'图片{idx} 下载并验证成功: {fname}')
    except Exception as e:
        print(f'图片{idx} 下载失败: {url} 错误: {e}')

print('\n图片有效性检测:')
for idx in range(1, 13):
    fname = f'ppt_imgs/{idx}.png'
    try:
        img = Image.open(fname)
        img.verify()
        print(f'{fname} 有效')
    except Exception as e:
        print(f'{fname} 无效: {e}') 